package config

import (
	"encoding/json"
	"os"
	"shyxy-net/common/application"
	"shyxy-net/common/consul"
	"shyxy-net/common/db/mysql"
)

type Config struct {
	ApplicationConfig *application.Config `json:"application"`
	ConsulConfig      *consul.Config      `json:"consul"`
	MysqlConfig       []*mysql.Config     `json:"mysql"`
}

func Loading(configPath string) (*Config, error) {
	var cfg Config
	var err error
	if _, err = os.Stat(configPath); err != nil {
		return nil, err
	}
	file, err := os.Open(configPath)
	if err != nil {
		return nil, err
	}
	decoder := json.NewDecoder(file)
	if err = decoder.Decode(&cfg); err != nil {
		return nil, err
	}
	return &cfg, nil
}
